package cn.lystudio.rohmtimeopwide_background_v11.controller.webApi;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import cn.lystudio.rohmtimeopwide_background_v11.entity.dto.SideBarMenuDTO;
import cn.lystudio.rohmtimeopwide_background_v11.service.SideBarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/webapi/sidebar")
@CrossOrigin
@Slf4j
public class SideBarController {
    private SideBarService sideBarService;

    @Autowired
    @Lazy
    public void setSideBarService(SideBarService sideBarService) {
        this.sideBarService = sideBarService;
    }


    @SaCheckLogin
    @GetMapping("/getSideBar")
    public List<SideBarMenuDTO> getSideBar(){
        List<String> roleList = StpUtil.getRoleList(StpUtil.getLoginIdAsString());
        List<SideBarMenuDTO> sideBar = sideBarService.getSideBar(Convert.toInt(roleList.get(0)));
        if(roleList.size() !=1) return null;
        return sideBar;
    }

}
